<template>
    <div>
        <template v-if="kuaijiList.length > 0">
            <statute
                v-for="(item, index) in kuaijiList"
                :key="index"
                :item="item"
                :tipEnable="true"
                @click="goDetail(item, 1)"
                @cancelCollect="cancelCollect"
            >
            </statute>
            <div v-if="count > 0" class="page">
                <el-pagination
                    background
                    layout="prev, pager, next"
                    :page-size="limit"
                    :total="count"
                    @current-change="changePage"
                >
                </el-pagination>
            </div>
        </template>

        <template v-else>
            <el-empty description="暂无数据"></el-empty>
        </template>
    </div>
</template>

<script>
import { getMyCollect, cancelLike } from "@/assets/api/userCenterApi.js";
import statute from "@/components/regulations/statute.vue";

export default {
    components: { statute },
    data() {
        return {
            page: 1,
            kuaijiList: [],
            limit: 10,
            count: 0,
        };
    },
    mounted() {
        this.getMyCollect();
    },
    methods: {
        //进详情
        goDetail(item) {
            this.$router.push({
                path: `/kjfgk/${item.id}.html`,
            });
        },

        //取消收藏
        async cancelCollect(e) {
            let params = {
                id: e.id,
            };
            let res = await cancelLike(params);
            this.showTipsIndex = -1;
            if (res.code == 1) {
                this.$message({
                    message: "取消收藏成功",
                    type: "success",
                });
                this.kuaijiList = [];
                this.page = 1;
                this.getMyCollect();
            }
        },
        async getMyCollect() {
            var params = {
                page: this.page,
                limit: this.limit,
                type: 7,
            };
            let res = await getMyCollect(params);
            if (res.code == 1) {
                this.kuaijiList = res.data.data;
                this.count = res.data.total;
            }
        },
        //分页
        changePage(e) {
            console.log("分页", e);
            this.page = e;
            this.getMyCollect();
        },
    },
};
</script>

<style lang="scss" scoped>
@import url("@/assets/static/reset.css");

.collectList {
    position: relative;
    padding: 20px;
    background-color: #fff;
    border-bottom: 1px solid #f4f4f4;

    .leaf {
        width: 11px;
        height: 18px;
        margin-right: 2px;
    }
    .leafNum {
        margin-right: 20px;
        color: #ff5900;
        font-size: 18px;
    }

    .title {
        width: 700px;
        font-size: 18px;
    }
    .info {
        font-size: 14px;
        margin-top: 30px;

        .time {
            color: #9e9e9e;
            margin-right: 20px;
        }
        .Effect {
            color: #9e9e9e;
            margin-right: 20px;
        }
    }
    .tips {
        cursor: pointer;
        position: absolute;
        top: 21px;
        right: 37px;

        img {
            width: 26px;
            height: 26px;
            vertical-align: middle;
        }
    }
}
.page {
    padding-top: 13px;
    padding-bottom: 63px;
    display: flex;
    justify-content: center;
}
</style>

<style lang="scss" scoped>
::v-deep .is-active {
    border-bottom-color: white !important;
}
</style>
